<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    var person = {
        personName:"zhangsan",
        age:20,
        sayHello:function(){
            console.log("hello");
        }
    }
    //第一种写法：最常用写法，格式：：：
    //对象.属性名
    //对象.方法名

    console.log(person.sayHello);//获得的是一个函数，函数不会运行
    person.sayHello();
    console.log(person.age);

    //第二种方法   对象.["属性名"]
    console.log(person["personName"]);
    person["sayHello"]();


    //区别  对象[变量]中括号中可以放变量

    var attr = "age";
    console.log(person[attr]);



    console.log(person.hoppy);//访问对象不存在 得到 undefined

    person.hoppy = ["阿萨德刚","fdzx"];
    console.log(person);
    //添加一个weight
    person["weight"] = "90kg";
    console.log(person);

    //修改属性值
    person.age = 60;
    person["age"] = 90;

    //删除属性
    delete person.age;
    console.log(person.age);
</script>
</html>